<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">  
    <head>  
        <title>增加角色</title>  
        <script src="/scripts/boot.js"></script>
    </head>  
    <body class="bg-white">
  		<div id="viewForm"  style="height:100%;overflow-y:auto;">
            <div class="title-info mb-20"><span>角色信息</span></div>
			<table class="table-bg" border="0" cellpadding="1" cellspacing="1" align="center" style="width:50%;margin: 0 auto; table-layout:fixed;">
				<colgroup>
					<col width="135px"></col>
					<col width="100%"></col>
				</colgroup>
				<tr>
					<td class="text-titlebg noEmpty">名称</td>
			        <td>
                        <input type="hidden" class="mini-hidden" name="id"/>
			        	<input name="roleName" class="mini-textbox w250"  required="true" vtype="maxLength:48" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"/>
			        </td>
			    </tr>
			  	<tr>
					<td class="text-titlebg noEmpty">标识</td>
			        <td>
			        	<input name="name" class="mini-textbox w250"  required="true" vtype="maxLength:48" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"/>
			        </td>
			    </tr>
			</table>
			<div class="mini-fit"></div>
			<div class="chose-toolbar">
		        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
		        <a class="chose-button save-button" onclick="view.save()">保存</a>
		    </div>
		</div>
		<script type="text/javascript">
            var post_flag,form,state;
            var view = {
                init: function () {
                    post_flag = false; //设置一个对象来控制是否进入AJAX过程
                    mini.parse();
                    form = new mini.Form("#viewForm");
                 
                },
                //保存
                save: function () {
                    form.validate();
                    if (form.isValid() == false) return;
                    if (post_flag) return;
                    var data = form.getData(true);//获取表单多个控件的数据
                    post_flag = true;
                    $.ajax({
                        url: (state=="new"?"/myRole/save":"/myRole/edit?id=" + data.id),
                        type: "post",
                        data: data,
                        success: function (msg) {
                        	if(!msg.state){
                        		post_flag = false;
                        		mini.alert(msg.message);
                        	}else{
                                CloseWindow("ok");
                        	}
                        },
                        error: function (errorMsg) {
                            post_flag = false;
                            var msg  = JSON.parse(errorMsg.responseText);
                            common.prompt(msg.message);
                        }
                    });
                },
            //    数据展示
                SetData: function (data) {
                    data = mini.clone(data);
                    state = data.state;
                    if(data.state=="edit"){
                        $.ajax({
                            url:"/myRole/info?id=" + data.id,
                            type: "post",
                            success: function (text) {
                            	text = $.parseJSON(text).body[0];
                                //跨页面传递的数据对象，克隆后才可以安全使用
                                var datas = mini.decode(text);   //反序列化成对象
                                form.setData(datas);             //设置多个控件数据
                            }
                        });
                    }else{
                        $("#editCode").hide();
                        $('input[name=id]').val("");
                    }
                }
            };
            view.init();
		</script>
    </body>  
</html>  